<?php
namespace app\ucentre\validate;

use think\Validate;

class Register extends Validate
{
    protected $rule =   [
    	'username' => 'require|checkName',
    	'password' => 'require|checkPwd',
    	'repassword' =>'require|confirm:password',
        'email' => 'require|email',
        'agreement' => 'accepted'
    ];
    
    protected $message  =   [
    	'username.require' => '用户名不能为空',
    	'password.require' => '密码不能为空',
    	'repassword.require' => '确认密码不能为空',
    	'repassword.confirm' => '2次密码不一致',
        'email'        => '邮箱格式错误',
        'agreement' => '请勾选同意网站服务条款'
    ];
    
    // 自定义用户名验证规则
    protected function checkName($value, $rule, $data=[])
    {

		if(strlen($value)<3){
			return "用户名必须是3-15个字符";
        }
        if(strlen($value)>15){
        	return "用户名必须是3-15个字符";
        }
    	return true;
    }
    
    // 自定义密码验证规则
    protected function checkPwd($value, $rule, $data=[])
    {

		if(strlen($value)<6){
			return "密码必须是6-15位";
        }
        if(strlen($value)>15){
        	return "密码必须是6-15位";
        }
        return true;
    }

}
?>